package com.gtxc.kotlinmvvm.ui.activity

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.text.TextUtils
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import com.aleyn.mvvm.base.BaseActivity
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.ToastUtils
import com.drake.statusbar.immersive
import com.gtxc.kotlinmvvm.BR
import com.gtxc.kotlinmvvm.R
import com.gtxc.kotlinmvvm.databinding.ActvitySplashatBinding
import com.gtxc.kotlinmvvm.viewmodle.StartViewModle

/**
 * FileName:SplashActivity
 * Author：Administrator
 * Date:2021 2021/9/27 19:46
 * Copyright (C), 2020-2021,成都拇音科技有限公司
 *
 *
 *
 *
 * Description: zwl
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
</desc></version></time></author> */
class SplashActivity : BaseActivity<StartViewModle, ActvitySplashatBinding>() {
    /**
     * 动画
     */
    var mAnimation: Animation? = null
    private var duration = 6
    private val updateHandler: Handler = object : Handler() {
        override fun dispatchMessage(msg: Message) {
            super.dispatchMessage(msg)
            if (msg.what == 3) {
                if (duration > 0) {
                    duration--
                    if (duration == 1) {
                        //用户自己的操作
                        if (TextUtils.isEmpty(SPUtils.getInstance().getString("token"))){
                            ToastUtils.showShort("token过期，请重新登录")
                            startActivity(Intent(this@SplashActivity, BTLoginActivity::class.java))
                        }else{
                            startActivity(Intent(this@SplashActivity, HomeActivity::class.java))
                        }
                    }
                    sendEmptyMessageDelayed(3, 1000)
                }
            }
        }
    }
    //在需要倒计时的地方执行以下代码
    override fun layoutId(): Int {
        return R.layout.actvity_splashat
    }

    override fun initView(savedInstanceState: Bundle?) {

        //直接调用，参数1是背景色，参数2是字体颜色（白色/黑色）
        this.isImmersive
        updateHandler.sendEmptyMessage(3);
    }

    override fun initData() {
        mAnimation = AnimationUtils.loadAnimation(this, R.anim.balloonscale)
        mBinding!!.imageView.animation = mAnimation
        mAnimation?.start()
    }

    override fun initCLick() {}
    override fun variableID(): Int {
        return BR.StartViewModle
    }

    override fun bindViewModel() {}
}